import request from '@/utils/request'
// request.post()返回值是promise对象
// 注册接口

export const login = data => request.post('authorizations', data)
// 短信封装
export const duanxin = (id) => request.get(`sms/codes/${id}`)

// 渲染用户
export const userInfo = () => request.get('user')

// 编辑个人资料
export const personal = () => request.get('user/profile')

// 修改头像
export const updatePhoto = (formData) => {
  return request({
    url: '/user/photo',
    method: 'patch',
    data: formData
  })
}
// export const updatePhoto = (formData) => request.patch('/user/photo', {
//   data: { formData }
// })

// 修改头像
// export const updatePhoto = (articleId, offset) => {
//   return request({
//     url: '/v1_0/comments',
//     params: { type: 'a', source: articleId, offset }
//   })
// }

// 修改昵称
// export const updateUser = (user) => request.patch('/v1_0/user/profile', user)
export const updateUser = (user) => {
  return request({
    url: '/user/profile',
    method: 'patch',
    data: user
  })
}
// 关注用户
// /**
//  * 关注 和 取消关注
//  * @param {*} authorId - 作者ID
//  * @param {*} isFollow - 是否关注
//  * @returns Promise
//  */
export const followAuthor = (authorId, isFollow) => {
  if (isFollow) {
    return request({
      url: 'user/followings',
      method: 'post',
      data: { target: authorId }
    })
  } else {
    return request({
      url: 'user/followings/' + authorId,
      method: 'delete'
      // data: { target: authorId }
    })
  }
}
